
<section class="news" id="news">
	<h3 class="title">{$category.name}</h3>
	<tag:article id="vo" limit="10" >
		<article class="news-item clearfix bb">
			<a href="{$vo.url}">
				<h4 class="mb5">{$vo.name}</h4>
				<notempty name="vo.pic">
				<div class="news-thumb"><img src="{$vo.pic}" /></div>
				</notempty>
				<div class="news-brief"><p>{$vo.description}</p></div>
			</a>
		</article>
	</tag:article>
	
	<php>$article_count = count($__tag_article__);</php>
	<gt name="article_count" value="10">
	<div class="auto tc mt10">
		<a id="read-more" class="btn btn-blue">更多</a>
	</div>
	</gt>
</section>
<script type="text/javascript">

	(function(){
		
		var readMore = document.getElementById( "read-more" ),
			news = document.getElementById("news"),
			page = 2,
			cat = {$_GET['id']},
			sid = {$_GET['sid']};
		
		readMore.addEventListener( "click", getMoreNews, false );
		
		function getMoreNews() {
			
			ajax("__CONTROLLER__/more", {p: page++, cat: cat, sid: sid}, function(data){
				if ( data.error == 0 ) {
					addArticle( data.extra )
				} else {
					cosole.log("获取失败。")
				}
			}, "post")
		}
	
		function addArticle( data ){
			
			if ( data.length ) {
				
				for(var i=0; at=data[i]; i++) {
					
					var article = document.createElement("article"),
						html = "",
						thumb = "";
					article.setAttribute("class", "clearfix bb");
					
					//是否含有缩略图
					thumb = at.pic.length ?  "<div class='thumb fl mr8 oh'><img src='" +at.pic+ "'/></div>" : "";
					
					html = 	"<a href='" +at.url+ "'>"
						   +"<h4 class='mb5'>" +at.name+ "</h4>"
						   +thumb
						   +"<div class='content'><p>"+ at.brief +"</p></div>"
						   +"</a>";
					
					article.innerHTML = html;
					
					news.insertBefore( article, readMore );
				
				}
			} else {
				readMore.innerHTML = "没有更多了……";
			}
		}
		//ajax(路径，数据，成功函数，提交方式)
		function ajax(url, json, fnSucc, type)
		{
			var oAjax;
			//创建ajax对象
			oAjax = new XMLHttpRequest();
			//发送的数据
			var data = "";
			for(var i in json)
			{
				data += i + "=" + json[i] + "&";
			}
			data = data.replace(/&$/,"");
			//GET或者POST
			if(type == "get")
			{
				oAjax.open("GET", url+"?"+data+new Date().getTime(), true);
				oAjax.send();
			}else if(type == "post")
			{
				oAjax.open("POST", url, true);
				oAjax.setRequestHeader("Content-type","application/x-www-form-urlencoded");
				oAjax.send(data);
			}
			oAjax.onreadystatechange = function()
			{
				if(oAjax.readyState == 4)
				{
					if(oAjax.status == 200)
					{
						//返回的json字符串转换为对象
						fnSucc(eval("("+oAjax.responseText+")"));
						
					}
				}
				
			}
		};
	})()
</script>